package com.newy.web.sys;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.newy.core.BaseController;
import com.newy.core.web.AppContext;
import com.newy.domain.sys.vo.ParamDef;
import com.newy.service.sys.ParamService;

/**
 * 系统/用户参数管理
 * @author linzongxue 2012-2-18
 *
 */
@Controller
@RequestMapping("sys/param")
public class ParamController extends  BaseController{
	@Resource private ParamService paramSvc;
	
	@RequestMapping("getAllSysParams") @ResponseBody
	public List<ParamDef> getAllSysParams(){
		return paramSvc.getAllSysParams();
	}
	
	@RequestMapping("getSysParam") @ResponseBody
	public void getSysParam(String name){
		outputText(paramSvc.getSysString(name));
	}
	
	@RequestMapping("getUserParam") @ResponseBody
	public void getUserParam(String name){
		outputText(paramSvc.getUserString(name, AppContext.getLoginUser().getId()));
	}

	/**
	 * 修改系统参数
	 */
	@RequestMapping("updateSysParam") @ResponseBody
	public void updateSysParam(String name, String value){
		paramSvc.updateSysParam(name, value);
	}
	
	/**
	 * 修改当前用户的用户参数
	 */
	@RequestMapping("updateUserParam") @ResponseBody
	public void updateUserParam(String name, String value){
		paramSvc.updateUserParam(name, value, AppContext.getLoginUser().getId());
	}

}
